package acwing;

import java.io.*;

public class A2 {

static int N=1010;
static int[] V=new int[N];//体积
static int[] W=new int[N];//价值
    static int[][] f=new int[N][N];
static int n;//物品数量
static int m;//背包容积
    static BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log=new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        String[] s = read.readLine().split(" ");
n=Integer.parseInt(s[0]);
m=Integer.parseInt(s[1]);
for(int i=1;i<=n;i++){
    String[] s1 = read.readLine().split(" ");
    V[i]=Integer.parseInt(s1[0]);
    W[i]=Integer.parseInt(s1[1]);
}
for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
        f[i][j]=f[i-1][j];
        if(j>=V[i])f[i][j]=Math.max(f[i-1][j],f[i-1][j-V[i]]+W[i]);
    }
}
log.write(Integer.toString(f[n][m]));
log.flush();
    }
}
